﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SHDQGSWEB.Controllers
{
    [HandleError]
    public class FileUploadController : Controller
    {
        [Authorize(Roles = "admin")]
        public ActionResult Index()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post),Authorize(Roles = "admin")]
        public ActionResult Uploading(HttpPostedFileBase uploadFile)
        {
            
            if (uploadFile.ContentLength > 0)
            {
                
                string fileName = Path.GetFileName(uploadFile.FileName);
                if (fileName != null)
                {

                    string filePath = Path.Combine(HttpContext.Server.MapPath("~/Content/Images/Products"), fileName
                        );

                    var files = new List<String> {fileName};
                    uploadFile.SaveAs(filePath);
                    return View("Uploading", files);
                }

            }
            return View("FileNotSet");
        }
    }
}
